import React, { Component } from 'react'
import Header from '../../Common/Header'
import { connect } from 'react-redux';
import { adddz_action } from '../../../store/store';
import { Toast } from 'antd-mobile';

class Xzdz extends Component {
    constructor() {
        super();
        this.state = {
            lxr: '',
            dh: '',
            dz: '',
            mph: ''
        }
    }

    render() {
        return (
            <div className="xzdz">
                <Header title="新增地址" back={<span onClick={() => { this.props.history.push({ pathname: '/shdz' }) }}>&lt;</span>}></Header>
                <div className="content">
                    <div className="lxr">联系人：<input type="text" placeholder="姓名" onChange={(e) => { this.setState({ lxr: e.target.value }) }} /></div>
                    <div className="dh"
                        onChange={(e) => {
                            this.setState({ dh: e.target.value })
                        }}>电话：<input type="text" placeholder="手机号码" />
                    </div>
                    <div className="dz"
                        onChange={(e) => { this.setState({ dz: e.target.value }) }}>
                        地址：<input type="text" placeholder="详细地址" />
                    </div>
                    <div className="mph"
                        onChange={(e) => { this.setState({ mph: e.target.value }) }}>
                        门牌号：<input type="text" placeholder="门牌号" />
                    </div>
                    <div className="bcbsy"
                        onClick={() => {
                            if (this.state.lxr && this.state.dz && this.state.mph && this.state.dh) {
                                this.props.dzlist(this.state);
                                Toast.success('新增成功', 1);
                                this.props.history.push({ pathname: '/shdz' })
                            } else {
                                Toast.fail('内容不能有空', 1, null, false)
                            }
                        }}>保存并使用
                     </div>
                </div>
            </div>
        )
    }
}
export default connect(
    (state) => {
        return {
        }
    },
    (dispatch) => {
        return {
            dzlist: (item) => { dispatch(adddz_action(item)) }
        }
    }
)(Xzdz)